package com.hx.vending.util;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.IOException;

/**
 * Created by Administrator on 2018/11/29.
 */
public class Base64Util {

    //加密
    public static String baseEncode(String str){
        try{
            BASE64Encoder base = new BASE64Encoder();
            String str1 = base.encode(str.getBytes("utf-8"));
            return str1;
        }catch(IOException e){
            e.printStackTrace();
        }
       return null;
    }

    //解密
    public static String baseDecoder(String str){
        BASE64Decoder bd = new BASE64Decoder();
        try{
            byte[] b = bd.decodeBuffer(str);
            String result = new String(b,"utf-8");
            return result;
        }catch(IOException e){
            e.printStackTrace();
        }
       return null;
    }
}
